<template>
  <div class="regulatory">
    <div class="regulatory_title">
      <p style="margin-right: 20px">教学规章</p>
    </div>
    <div class="regulatory_table">
      <el-table :data="courseList" style="width: 100%">
        <el-table-column fixed prop="title" label="名称"> </el-table-column>
        <el-table-column label="类型" width="200">
           <template slot-scope="scope">
             <span v-if="scope.row.subject === 'regulation'">教学规章</span>
             <span v-if="scope.row.subject === 'others'">其他法规</span>
             <span v-if="scope.row.subject === 'research'">科研文件</span>
                  </template>
        </el-table-column>
        <el-table-column prop="createdAt" label="创建日期" width="200">
        </el-table-column>
        <el-table-column prop="updatedAt" label="更新日期" width="200">
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="regulatory_pagination">
         <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="courseData.page"
        :page-size="courseData.size"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getCourseList } from "@/api/course";
export default {
  name: "regulatory",
  data() {
    return {
      routerName: "",
      courseData: {
        page: 1,
        size: 10,
        data: {
          keyword: "",
          subject: "",
        },
      },
      courseList: [],
      total: 0,
    };
  },
  created() {
    this.routerName = this.$route.query.routerName;
  },
  mounted() {
    this.courseData.data.subject = this.$route.query.type;
    this.getCourseList(this.courseData);
  },
  methods: {
    // 获取列表
    getCourseList(data) {
      getCourseList(data).then((response) => {
        if (response.data.code === 20000) {
          const { list, totalRecords } = response.data.results;
          this.total = totalRecords;
          this.courseList = list;
        }
      });
    },
    handleClick(row) {
      console.log(row);
      this.$router.push({
        path: "/discipline/regulatoryDetail",
        query: {
          routerName: this.routerName,
          courseId: row.id,
        },
      });
    },
      handleCurrentChange(val) {
      this.courseData.page = val;
      this.getCourseList(this.courseData);
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.regulatory {
  .regulatory_title {
    height: 40px;
    background: #f1f1f1;
    text-align: right;
    line-height: 40px;
    font-weight: bold;
    font-size: 21px;
    color: #0a7b19;
  }
  .regulatory_table {
    margin-top: 20px;
    margin-bottom: 50px;
    .el-button--text {
      color: #0a7b19;
    }
  }
  .regulatory_pagination {
    width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    margin-bottom: 50px;
    .regulatory_pagination_button {
      width: 86px;
      height: 38px;
      line-height: 38px;
      border: 1px solid #0a7b19;
      border-radius: 8px;
      color: #0a7b19;
      font-weight: bold;
      text-align: center;
      transition: all 0.2s linear;
      cursor: pointer;
      &:hover {
        background-color: #0a7b19;
        color: white;
      }
    }
  }
}
</style>
